#include <vector>

using namespace std;

class Solution {
public:
    int pivotIndex(vector<int>& nums) {
        int leftSum = 0, rightSum = 0;
        for (auto& it : nums) rightSum += it;
        int resPos = 0;
        for (; resPos < nums.size(); ++resPos) {
            rightSum -= nums[resPos];
            if (leftSum == rightSum) return resPos;
            leftSum += nums[resPos];
        }
        return -1;
    }
};